home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8232 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: rap.SanDiegoCA.ATTGIS.COM!es013!jbc
  2. From: jbc@ElSegundoCA.ATTGIS.COM (Jim Chapman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: No struct in C++!!?
  5. Date: 15 Feb 1996 22:36:54 GMT
  6. Organization: AT&T Global Information Solutions
  7. Distribution: world
  8. Message-ID: <4g0ci6$t55@rap.SanDiegoCA.ATTGIS.COM>
  9. References: <31235E0C.252C@idi.oclc.org>
  10. Reply-To: jbc@ElSegundoCA.ATTGIS.COM
  11. NNTP-Posting-Host: es013.elsegundoca.attgis.com
  12.  
  13. In article 252C@idi.oclc.org, Ron Unterreiner <runterreiner@idi.oclc.org> () writes:
  14. > Georg Woste wrote:
  15. > > 
  16. > > Hi,
  17. > > 
  18. > > a beginners question: I found in different C++ books examples of C++ programms
  19. > > which contain type declarations and definitions in the main() programm - for
  20. > > example a struct  - as in C.
  21. > > My question is, whether this is a contradiction
  22. > > to the paradigm of C++. Shouldn't be everything in a C++ programm
  23. > > either classes, objects or the interaction between objects?
  24. > > So is it bad C++ style, to use functions or data outside from
  25. > > classes (objects)?
  26. > > 
  27. > > Thanks!
  28. > > 
  29. > > Georg Woeste
  30.  
  31. > A class is a struct.  Anywhere you see the word struct you can substitute 
  32. > the word class.  [..]
  33.  
  34. Correct so far.
  35.  
  36. > [..]  The major thing a class gives you that a C struct 
  37. > doesn't is the ability to protect data.  [rest deleted]
  38.  
  39. Not true. The only difference is the *default* encapsulation level.  Struct
  40. and class are fundamentally interchangable.  The following two definitions
  41. are absolutely equivalent:
  42.  
  43.    struct Foo { // stuff... };
  44.    classs Foo { public: // stuff... };
  45.  
  46. It is also perfectly legitimate to alternate usage 'struct' and 'class' with
  47. the same typename, like this:
  48.  
  49.    class Foo;           // forward declaration of Foo as class
  50.    struct Foo { ... };  // definition of Foo as struct
  51.  
  52. ---------------
  53. Jim Chapman                        NCR Corporation
  54. jbc@ElSegundoCA.NCR.COM            Parallel Systems Division
  55.  
  56.